<?php
class Tag extends Model{
	protected $table_name = 'tag';
	
	public function test(){
		echo 'Tag model test!<br/>';
	}
	
	//增加一个新标签  检重->插入标签/返回__halt_compiler
	public function add_tag($tag){
		$tag = trim($tag);
		$re = $this->find(array('tag'=>$tag),'id');
		if(!empty($re['id'])) {
			return $re['id'];
		}else {
			return $this->insert(array('tag'=>$tag));
		}
	}
	
	public function add_tags($tags){
		if(is_string($tags)) {
			$tags = preg_split('#,|，| | #',$tags);
		}
		$tags = array_diff($tags,array(''));
		$ids = '';
		foreach($tags as $tag) {
			$id = $this->add_tag($tag);
			$ids []= $id;
		}
		return $ids;
	}
	

	
	//标签计数+1
	public function inr($tag_id) {
		$this->query("update $this->table_name set `count`=`count`+1 where id=$tag_id limit 1");
	}
	
	
	
	
	
}
?>